/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package recursionassignment.des.assignment3;

import javax.swing.JOptionPane;

/**
 *
 * @author k00104663
 */
public class Functions {
    /* Function to raise x to the power n.*/
static double power(double base, int power) {
  if(power == 0)
    return 1.0;
  else
    return base * power( base , power - 1 );
}

public static void exit(){
    int exit = JOptionPane.showConfirmDialog(null, "Are you sure?");
 if (exit == JOptionPane.YES_OPTION){
     try{
         System.exit(exit);
     }
     catch(Exception e){
         JOptionPane.showMessageDialog(null, "An Exception Occured: "+e.getMessage());
     }
 }
 if(exit==JOptionPane.NO_OPTION){
     JOptionPane.showMessageDialog(null, "Returning to Program!");
 }
 if(exit==JOptionPane.CANCEL_OPTION){
     JOptionPane.showMessageDialog(null, "Returning to Program!");
 }
}//GEN-LAST:event_jButton9ActionPerformed

public static long gcd(int a, int b){
    // this will find the greatest common divisor of two numbers. 
    if (b==0) 
      return a; 
    else
      return gcd(b, a % b); 
}


public static long factorial(long number){
    // function to calculate factorial of a positive number
    
if(number == 0)
     
    return 1;
else{
    return(number*(factorial(number-1))); // number by number -1 by number by number -1 etc
       
}
}

public static int place(int number) {
   if(number == 0) {
      return 1;
   } else {
      return 10 * place(number / 10);
   }
}


}
